<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/13
  Time: 16:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/laypage/laypage.js"></script>
<script type="text/javascript" src="/js/layer/layer.js"></script>
<script type="text/javascript" src="/js/vue/vue.min.js"></script>
<script type="text/javascript" src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<style>
    input.error {
        border: 1px solid red;
    }
</style>
<body>
<div class="container">
    <form id="editDeptForm">
        <br/>
        <div class="form-group">
            <label for="dname">部门名称：</label>
            <input type="text" class="form-control" id="dname" name="dname" value="${dept.dname}"
                   placeholder="输入名称">
        </div>
        <div class="form-group">
            <label for="loc">部门地址：</label>
            <input type="text" class="form-control" id="loc" name="loc" value="${dept.loc}" placeholder="输入地址">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>

    var editDept = function () {
        if(!check().form()){
            return ;
        }
        $.ajax({
            type:'GET',
            dataType:"json",
            url:"/json/editDept",
            data:{
                deptid:${dept.deptid},
                dname:$("#dname").val(),
                loc:$("#loc").val()
            },
            success:function () {
                $("#cancelBtn").click();
            }
        });
    }

    //点击提交按钮，触发
    $("#saveBtn").on("click",function () {
        editDept();
    })

    //关闭遮罩层，更新页面信息
    $("#cancelBtn").on("click",function () {
        var index = parent.layer.getFrameIndex(window.name);
        //更新页面信息
        /*parent.getDeptPageList();*/
        parent.layer.close(index);
    })

    function check() {
        return $("#editDeptForm").validate({
            rules:{
                dname:{
                    required : true
                },
                loc:{
                    required : true
                }
            },
            messages:{
                dname:{
                    required : ""
                },
                loc:{
                    required : ""
                }
            }
        })
    }
</script>
